/**
 * 失业人员客观原因减少
 */ 
var orgData = _appConfigs.getUserData().userOrgs;
$(function(){
	$("#JoblessReduce_street").combobox({
		data:$.appCache.get("dict_street"),
		valueField:'code',    
	    textField:'name',
	    editable:false,
	    panelMaxHeight:90,
	    onSelect: function(record){
	        $("#JoblessReduce_community").combobox({
	          url:'application/dict/getSubMenu',
	          queryParams:{
	            tableName:'dict_community',
	            parent_code:record.code
	          },
	          valueField:'code',    
	          textField:'name',
	          missingMessage:'必填',
	          editable:false,
	          panelMaxHeight:90
	        }); 
	      }
	});
});
/**
 * 默认选街道
 */
if(orgData.porgId == _appConfigs.appOrgId){
	  $('#JoblessReduce_street').combobox({disabled:true});
	  $('#JoblessReduce_street').combobox('select',orgData.orgId);
}else if(orgData.porgId != _appConfigs.appOrgId && orgData.orgName.indexOf('社区')>=0){
  $('#JoblessReduce_street').combobox({disabled:true});
  $('#JoblessReduce_community').combobox({disabled:true});
  $('#JoblessReduce_street').combobox('select',orgData.porgId);
  $('#JoblessReduce_community').combobox('select',orgData.orgId);
}else{
  $("#JoblessReduce_community").combobox({
    data:$.appCache.get('dict_community'),
    valueField:'code',    
      textField:'name',
      editable:false,
      panelMaxHeight:90
  }); 
}
$('#joblessReduceGrid').datagrid({ 
    url:'jobless/management/getJoblessReduce',
    queryParams:{
    	street: $('#JoblessReduce_street').combobox('getValue'),
		community: $('#JoblessReduce_community').combobox('getValue')
    },
    idField:'unemployedId',
    rownumbers:true,
    fitColumns:true,
    singleSelect:true,
    pagination:true,
    columns:[[  
              {field:'unemployedId',title:'主键',hidden:'true'}, 
              {field:'name',title:'姓名',width:90,align:'center'}, 
              {field:'sex',title:'性别',width:60,align:'center',
            	     formatter:function(value){
            	    	 var dict = $.appCache.get('dict_gender');
           		         if(!dict|| !dict.length) {
           		        	 return value;
           		         } else {
           		        	 var i = 0;
               		         for(i; i<dict.length; i++) {
               		        	 var data = dict[i];
               			         if(value == data.code) {
               			        	 return data.name;
               			         }
               		         }
           		         }
           	         }},  
              {field:'idcard',title:'身份证号',width:130,align:'center'},
              {field:'phone',title:'联系方式',width:100,align:'center'}, 
              {field:'education',title:'学历',width:80,align:'center',
            	     formatter:function(value){
            	    	 var dict = $.appCache.get('dict_education');
        		         if(!dict || !dict.length) {
        		        	 return value;
        		         } else {
        		        	 var i = 0;
            		         for(i; i<dict.length; i++) {
            		        	 var data = dict[i];
            			         if(value == data.code) {
            			        	 return data.name;
            			         }
            		         }
        		         }
        	         }},         	       
        	  {field:'unemploymentdate',title:'失业时间',width:90,align:'center',
        	    	   formatter:function(data){ 
        	    		   if(data!=null){
        	    			   var df = new Date(data);  
                             return df.format("yyyy-MM-dd");       			   
            		       } else{
            		    	   return null;
            		       }
            	       }},         	   
              {field:'knry',title:'困难人员',width:90,align:'center',
            	       formatter:function(data){
            	    	   if(data==1)
            	    		   return "是";
            	    	   else
            	    		   return "";
           	       }},          	 
              {field:'intention',title:'择业意向',width:90,align:'center'},
              {field:'trackingtime',title:'跟踪时间',hidden:'true'},	  
              {field:'removereason',title:'减少原因',width:110,align:'center',
            	     formatter:function(value){
            	    	 var dict = $.appCache.get('dict_removereason');
        		         if(!dict || !dict.length) {
        		        	 return value;
        		         } else {
        		        	 var i = 0;
            		         for(i; i<dict.length; i++) {
            		        	 var data = dict[i];
            			         if(value == data.code) {
            			        	 return data.name;
            			         }
            		         }
        		         }
        	         }},  
              {field:'removedate',title:'减少时间',width:90,align:'center',
           	       formatter:function(data){
           	    	   if(data!=null){
           	    		   var df = new Date(data);  
                             return df.format("yyyy-MM-dd");       			   
      		           } else{
      		        	   return null;
      		           }
      	           }},  
              {field:'street',title:'街道',width:100,align:'center',
      	        	 formatter:function(value){
              		   var dict = $.appCache.get('dict_street');
                         if(!dict || !dict.length) {
                      	   return value;
                         } else {
                      	   var i = 0;
                             for(i; i<dict.length; i++) {
                          	   var data = dict[i];
                           	   if(value == data.code) {
                           		   return data.name;
                           	   }
                             }
                         }
                     }},  	   
              {field:'community',title:'社区',width:120,align:'center',
                     formatter:function(value){ 
                    	 var dict = $.appCache.get('dict_community');
                         if(!dict || !dict.length) {
                        	 return value;
                         } else {
                        	 var i = 0;
                        	 for(i; i<dict.length; i++) {
                        		 var data = dict[i];
                        		 if(value == data.code) {
                        			 return data.name;
                                 }
                             }
                         }
                     }},  
              {field:'remark',title:'备注',width:80,align:'center'}
          ]]   
});

/**
 * 查询条件
 */
function reduceSearch(){
	$('#joblessReduceGrid').datagrid('load',{
		street: $('#JoblessReduce_street').combobox('getValue'),
		community: $('#JoblessReduce_community').combobox('getValue'),
		name: $('#JoblessReduce_name').val(),	
		idcard: $('#JoblessReduce_idCard').val() 					
	});
}

function exportJoblessReduce(){
	var street,community;
	 if(orgData.porgId == _appConfigs.appOrgId){  //街道
		 street = orgData.orgId;
		 community = "";
	 }else if(orgData.porgId != _appConfigs.appOrgId && orgData.orgName.indexOf('社区')>=0){ //社区
		 street = "";
		 community = orgData.orgId;
	 }else{  //全部
		 street = "";
		 community = "";
	 }
	window.location.href ="jobless/excel/exportJoblessReduce?street="+street+"&community="+community;
}